package app.netant.galgame.bangumi.game;

import cn.lily.com.db.sql.manager.DBOfflineManager;
import cn.lily.com.lang.number.MathUtil;

/**
 * 游戏实体处理
 * @author JiaJ
 * @date 2018年6月14日
 *
 */
public class BangumiGameEntity {
	
	private String gameID = System.currentTimeMillis()+""+MathUtil.random(3)+"";
	private String gameName = "";
	private String gameMemo = "";
	private String gameURL = "";
	private String gameTag = "";
	private String gameNameOth = "";
	private String gameUrlSt = "";
	private String gameSale = "";
	private String gameIssuer = "";
	private String gameMaker = "";
	private String gameCGs = "";
	private String gameDate = "";
	private String gameDoctor = "";
	private String gameWriter = "";
	private String gamePictor = "";
	private String gameType = "";
	private String gameScene = "";
	private String gameCast = "";
	private String gameLang = "";
	private String gameEnds = "";
	private String gameTimeout = "";
	private String gameOpera = "";
	private String gameMusic = "";
	private String gameOs = "";
	private String gameEngine = "";
	private String gameAge = "";
	private String gameCero = "";
	
	public void setGameID(String gameID) {
		if(this.gameID == null ||"".equals(this.gameID)){
			this.gameID = gameID;
		}else{
			this.gameID += "," + gameID;
		}	
	}
	public void setGameName(String gameName) {
		if(this.gameName == null || "".equals(this.gameName)){
			this.gameName = gameName;
		}else{
			this.gameName += "," + gameName;
		}
	}
	public void setGameMemo(String gameMemo) {
		if(this.gameMemo == null || "".equals(this.gameMemo)){
			this.gameMemo = gameMemo;
		}else{
			this.gameMemo += "," + gameMemo;
		}
	}
	public void setGameURL(String gameURL) {
		if(this.gameURL == null || "".equals(this.gameURL)){
			this.gameURL = gameURL;
		}else{
			this.gameURL += "," + gameURL;
		}
	}
	public void setGameTag(String gameTag) {
		if(this.gameTag == null || "".equals(this.gameTag)){
			this.gameTag = gameTag;
		}else{
			this.gameTag += "," + gameTag;
		}
	}
	public void setGameNameOth(String gameNameOth) {
		if(this.gameNameOth == null || "".equals(this.gameNameOth)){
			this.gameNameOth = gameNameOth;
		}else{
			this.gameNameOth += "," + gameNameOth;
		}
	}
	public void setGameUrlSt(String gameUrlSt) {
		if(this.gameUrlSt == null || "".equals(this.gameUrlSt)){
			this.gameUrlSt = gameUrlSt;
		}else{
			this.gameUrlSt += "," + gameUrlSt;
		}
	}
	public void setGameSale(String gameSale) {
		if(this.gameSale == null || "".equals(this.gameSale)){
			this.gameSale = gameSale;
		}else{
			this.gameSale += "," + gameSale;
		}
	}
	public void setGameIssuer(String gameIssuer) {
		if(this.gameIssuer == null || "".equals(this.gameIssuer)){
			this.gameIssuer = gameIssuer;
		}else{
			this.gameIssuer += "," + gameIssuer;
		}
	}
	public void setGameMaker(String gameMaker) {
		if(this.gameMaker == null || "".equals(this.gameMaker)){
			this.gameMaker = gameMaker;
		}else{
			this.gameMaker += "," + gameMaker;
		}
	}
	public void setGameCGs(String gameCGs) {
		if(this.gameCGs == null || "".equals(this.gameCGs)){
			this.gameCGs = gameCGs;
		}else{
			this.gameCGs += "," + gameCGs;
		}
	}
	public void setGameDate(String gameDate) {
		if(this.gameDate == null || "".equals(this.gameDate)){
			this.gameDate = gameDate;
		}else{
			this.gameDate += "," + gameDate;
		}
	}
	public void setGameDoctor(String gameDoctor) {
		if(this.gameDoctor == null || "".equals(this.gameDoctor)){
			this.gameDoctor = gameDoctor;
		}else{
			this.gameDoctor += "," + gameDoctor;
		}
	}
	public void setGameWriter(String gameWriter) {
		if(this.gameWriter == null || "".equals(this.gameWriter)){
			this.gameWriter = gameWriter;
		}else{
			this.gameWriter += "," + gameWriter;
		}
	}
	public void setGamePictor(String gamePictor) {
		if(this.gamePictor == null || "".equals(this.gamePictor)){
			this.gamePictor = gamePictor;
		}else{
			this.gamePictor += "," + gamePictor;
		}
	}
	public void setGameType(String gameType) {
		if(this.gameType == null || "".equals(this.gameType)){
			this.gameType = gameType;
		}else{
			this.gameType += "," + gameType;
		}
	}
	public void setGameScene(String gameScene) {
		if(this.gameScene == null || "".equals(this.gameScene)){
			this.gameScene = gameScene;
		}else{
			this.gameScene += "," + gameScene;
		}
	}
	public void setGameCast(String gameCast) {
		if(this.gameCast == null || "".equals(this.gameCast)){
			this.gameCast = gameCast;
		}else{
			this.gameCast += "," + gameCast;
		}
	}
	public void setGameLang(String gameLang) {
		if(this.gameLang == null || "".equals(this.gameLang)){
			this.gameLang = gameLang;
		}else{
			this.gameLang += "," + gameLang;
		}
	}
	public void setGameEnds(String gameEnds) {
		if(this.gameEnds == null || "".equals(this.gameEnds)){
			this.gameEnds = gameEnds;
		}else{
			this.gameEnds += "," + gameEnds;
		}
	}
	public void setGameTimeout(String gameTimeout) {
		if(this.gameTimeout == null || "".equals(this.gameTimeout)){
			this.gameTimeout = gameTimeout;
		}else{
			this.gameTimeout += "," + gameTimeout;
		}
	}
	public void setGameOpera(String gameOpera) {
		if(this.gameOpera == null || "".equals(this.gameOpera)){
			this.gameOpera = gameOpera;
		}else{
			this.gameOpera += "," + gameOpera;
		}
	}
	public void setGameMusic(String gameMusic) {
		if(this.gameMusic == null || "".equals(this.gameMusic)){
			this.gameMusic = gameMusic;
		}else{
			this.gameMusic += "," + gameMusic;
		}
	}
	public void setGameOs(String gameOs) {
		if(this.gameOs == null || "".equals(this.gameOs)){
			this.gameOs = gameOs;
		}else{
			this.gameOs += "," + gameOs;
		}
	}
	public void setGameEngine(String gameEngine) {
		if(this.gameEngine == null || "".equals(this.gameEngine)){
			this.gameEngine = gameEngine;
		}else{
			this.gameEngine += "," + gameEngine;
		}
	}
	public void setGameAge(String gameAge) {
		if(this.gameAge == null || "".equals(this.gameAge)){
			this.gameAge = gameAge;
		}else{
			this.gameAge += "," + gameAge;
		}
	}
	public void setGameCero(String gameCero) {
		if(this.gameCero == null || "".equals(this.gameCero)){
			this.gameCero = gameCero;
		}else{
			this.gameCero += "," + gameCero;
		}
	}
	
	public void addTagValue(String tagName,String tagValue){
		
		tagName = tagName.trim();
		tagValue = this.getString(tagValue.trim());
		
		if("CERO".equals(tagName)){
			this.setGameCero(tagValue);
		}
		
		else if("网址".equals(tagName) || "官方网站".equals(tagName)){
			this.setGameUrlSt(tagValue);
		}
		
		else if("售价".equals(tagName)){
			this.setGameSale(tagValue);
		}
		
		else if("分辨率".equals(tagName) || "画面尺寸".equals(tagName)){
			this.setGameScene(tagValue);
		}
		
		else if("结局数".equals(tagName) || "ED数".equals(tagName)){
			this.setGameEnds(tagValue);
		}
		
		else if("CG数".equals(tagName)){
			this.setGameCGs(tagValue);
		}
		
		else if("语言".equals(tagName)){
			this.setGameLang(tagValue);
		}
		
		else if(tagName.indexOf("作画")>-1
			  ||tagName.indexOf("美工")>-1
			  ||tagName.indexOf("原画")>-1){
			this.setGamePictor(tagValue);
		}
		
		else if("原作".equals(tagName)
			  ||"剧本".equals(tagName)
			  ||"脚本".equals(tagName)
			  ||"企画".equals(tagName)
			  ||"シナリオ".equals(tagName)){
			this.setGameWriter(tagValue);
			this.setGameOpera(tagValue);
		}
		
		else if("游戏引擎".equals(tagName)){
			this.setGameEngine(tagValue);
		}
		
		else if("游戏类型".equals(tagName)){
			this.setGameType(tagValue);
		}
		
		else if(tagName.indexOf("发行日期")>-1){
			this.setGameDate(tagValue);
		}
		
		else if(tagName.indexOf("游戏用时")>-1){
			this.setGameTimeout(tagValue);
		}
		
		else if(tagName.indexOf("导演")>-1){
			this.setGameDoctor(tagValue);
		}
		
		else if(tagName.indexOf("年龄")>-1){
			this.setGameAge(tagValue);
		}
		
		else if("平台".equals(tagName) || "動作環境".equals(tagName) || "游戏平台".equals(tagName)){
			this.setGameOs(tagValue);
		}
		
		else if("声优".equals(tagName) || "CAST".equals(tagName.toUpperCase())){
			this.setGameCast(tagValue);
		}
		
		else if("别名".equals(tagName) || "中文名".equals(tagName)){
			this.setGameNameOth(tagValue);
		}
		
		else if(tagName.indexOf("音乐")>-1 
			 || tagName.indexOf("作曲")>-1
			 || tagName.indexOf("作词")>-1){
			this.setGameMusic(tagValue);
		}
		
		else if("制作社团".equals(tagName) 
			 || "制作公司".equals(tagName)
			 || "制作人".equals(tagName)
			 || "游戏开发".equals(tagName)
			 || "游戏制作".equals(tagName)
			 || "制作者".equals(tagName)
			 || "制作".equals(tagName)
			 || "开发商".equals(tagName)
			 || "开发".equals(tagName)
			 || "作者".equals(tagName)
			 || "开发者".equals(tagName)){
			this.setGameMaker(tagValue);
		}
		
		else if("发行".equals(tagName)
			  ||"发行公司".equals(tagName)
			  ||"游戏出版商".equals(tagName)
			  ||"出版商".equals(tagName)
			  ||"出版".equals(tagName)
			  ||"游戏发行".equals(tagName)
			  ||"销售商".equals(tagName)){
			this.setGameIssuer(tagValue);
		}
	}
	
	public void insert() {
			
		/*if(this.gameName == null || "".equals(this.gameName)){
			return;
		}*/
		
		String insertSQL = " insert into ${schema}.LEO_BANGUMI_GAME_INFO "
				                      + " (GAME_ID,GAME_NAME,GAME_URL,GAME_MEMO,GAME_TAG,GAME_NAME_OTH,"
				                      + "GAME_URL_ST,GAME_SALE,GAME_ISSUER,GAME_MAKER,GAME_CGS,GAME_DATE,"
				                      + "GAME_DOCTOR,GAME_WRITER,GAME_PICTOR,GAME_TYPE,GAME_SCENE,GAME_CAST,"
				                      + "GAME_LANG,GAME_ENDS,GAME_TIMEOUT,GAME_OPERA,GAME_MUSIC,GAME_OS,"
				                      + "GAME_ENGINE,GAME_AGE,GAME_CERO) "
				                      + " values "
				                      + " ('"+gameID+"','"+gameName+"','"+gameURL+"','"+gameMemo+"','"+gameTag+"','"+gameNameOth+"',"
				                        + "'"+gameUrlSt+"','"+gameSale+"','"+gameIssuer+"','"+gameMaker+"','"+gameCGs+"','"+gameDate+"',"
				                        + "'"+gameDoctor+"','"+gameWriter+"','"+gamePictor+"','"+gameType+"','"+gameScene+"','"+gameCast+"',"
				                        + "'"+gameLang+"','"+gameEnds+"','"+gameTimeout+"','"+gameOpera+"','"+gameMusic+"','"+gameOs+"',"
				                        + "'"+gameEngine+"','"+gameAge+"','"+gameCero+"'"
				                      + ") ";
		
		DBOfflineManager.getDBManager().executeUpdate(insertSQL);
		
	}
	
	protected String getString(String src){
		return src.replaceAll("'", "’")
				  .replaceAll("\"", "”")
				  .replaceAll("&nbsp;", "")
				  .replaceAll("<br>", "")
				  .replaceAll("<br/>", "")
				  .replaceAll("<p>", "")
				  .replaceAll("</p>", "");
	}
}
